package com.zhao.biz.tag.perform

import org.apache.commons.lang3.StringUtils
import org.apache.spark.broadcast.Broadcast
import org.apache.spark.sql.Row

/**
 * Description: APP标签<br/>
 * Copyright (c) ，2021 ， 赵 <br/>
 * A wet person does not fear the rain. <br/>
 * Date： 2021/1/14 14:00
 *
 * @author 柒柒
 * @version : 1.0
 */

object TagsApp extends IMakeTags {
  /**
   * 数据标签接口
   *
   * @param args
   * @return
   */
  override def makeTags(args: Any*): List[(String, Int)] = {
    var list: List[(String, Int)] = List[(String, Int)]()

    //Row是一个类型,和Car,Person这些类型一样,所有的表结构信息都用Row来表示
    val row = args(0).asInstanceOf[Row]
    val appdic: Broadcast[Map[String, Int]] = args(1).asInstanceOf[Broadcast[Map[String, Int]]]

    //获取APPname,appid
    val appname = row.getAs[String]("appname")
    val appid = row.getAs[String]("appid")

    if (StringUtils.isNoneBlank(appname)) {
      list :+= ("APP" + appname,1)
    } else {
      //若appid不为空,从广播变量中根据appID获取对应的appName
      list :+= ("APP" + appdic.value.getOrElse(appid,if (appid.isEmpty) "未知" else appid),1)
    }
    list
  }
}



















